package com.example.demo.controller;


import com.example.demo.pojo.Classes;
import com.example.demo.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ClassesController {

    @Autowired
    private ClassesService classesService;
    /*查询所有班级*/

    @RequestMapping(value = "/queryClass",method = RequestMethod.POST)
    public List<Classes> queryAllClass(){
       return classesService.queryAllClass();
    }

    @RequestMapping("queryone")
    public Classes queryone(int id){
        return classesService.queryone(id);
    }
    /*增加班级*/
    @RequestMapping(value = "/addClass" ,method = RequestMethod.POST)
    public String addClass(String class_name,String grade,String classs){


        if (class_name==""||grade==""||classs=="")
        {

            return "增加班级失败";

        }
        else {
            classesService.addClass(class_name,grade,classs);
            return "增加班级成功";
        }

    }
    /*修改班级*/
    @RequestMapping(value = "/updateClass" ,method = RequestMethod.POST)
    public String updateClass (Classes classes){
        if (classes!=null){
            classesService.updateClass(classes);
            return "修改成功";
        }
        else {
            return "修改失败";
        }
    }
    /*删除班级*/
    @RequestMapping(value = "/deleteClass",method = RequestMethod.POST)
    public String deleteClass(Integer id){
        if (id!=null){
            classesService.deleteClass(id);
            return "删除成功";
        }
        else {
            return "删除失败";
        }

    }



}
